

/*------------------------------------------------------------------------------
	1. Housekeeping
------------------------------------------------------------------------------*/

	*Run housekeeping code
		qui do ".../replication_package/housekeeping.do"

	*Write log
		log using "$log_loc/figure_a7.log", text replace

/*------------------------------------------------------------------------------
	2. Clean Main dataset
------------------------------------------------------------------------------*/

		*Import Data
		use "$data/childrens2018_w_w2.dta", clear
			drop _merge

			/*Restrict Sample*/
				*Keep f1095 filings
					rename state_insurance state
					fmerge m:1 state using "$data/statelist.dta"
						assert _merge != 2 //Confirm that all 51 states are in dataset
						drop if _merge != 3
						drop _merge

				*Keep if age_num is within the range
					keep if age_num >= 0 & age_num <= 16

				*Keep if kid died after end of year or is currently alive
					keep if 2018*10000+1231<death_date|death_date==0

				*Keep if months covered is possible
					keep if num_cov_ins > 0 & num_cov_ins <= 12
	
			/*Generate variables for figure*/
				*Generate outcome variable on claiming
					gen onreturn = file_inc != .

				*Generate a ct variable
					gen ct = 1

				*Rescale Claimed Variable to be between 1 and 100
					replace onreturn = onreturn * 100

				*Create outcome for joint income
					gen tot_med_wage_nums = dad_med_wage_nums + mom_med_wage_nums

				*Adjust for claiming limits
					replace onreturn = onreturn * 1.0017029

/*------------------------------------------------------------------------------
	4. Create Figures
------------------------------------------------------------------------------*/

			/*Generate figures*/
				*Create Binned Scatter Plots
					binscatter onreturn tot_med_wage_nums if tot_med_wage_nums > 0 & tot_med_wage_nums < 200000, nq(100) ///
						xtitle("Wages ($)") ytitle("% Children Claimed") ///
						xlabel(0(40000)200000, format(%10.0fc) labsize(small)) linetype(none)

					*Save out Figure
						graph export "${output}/2018 joint income 200k.png", replace as(png)
						